﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "unistd.h"

float g_fHeading = 0; // 航向
float g_fPitch = 0;   // 俯仰
float g_fRoll = 0;    // 横滚

int g_calibrationl = 0;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow),
      m_tabs(new QtMaterialTabs),
      m_drawer(new QtMaterialDrawer)
{
    ui->setupUi(this);
    init_form();
    qDebug() << sizeof(pack_Control_To_PC_Sonar_data);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::model_select()
{
    int i = 0;
    m_drawer->setParent(this); // 设置抽屉界面属于主窗口，永远在最前端
    m_drawer->setClickOutsideToClose(true);
    m_drawer->setOverlayMode(true);
    QVBoxLayout *drawerLayout = new QVBoxLayout;
    m_drawer->setDrawerLayout(drawerLayout);
    QVector<QString> labels = {"modle1", "modle2", "modle3", "modle4"}; // 型号增添
    QVector<QString>::iterator it;
    for (it = labels.begin(); it != labels.end(); ++it)
    {
        modelButton[i] = new QtMaterialRaisedButton(*it);
        modelButton[i]->setMinimumHeight(30);
        modelButton[i]->setFont(QFont("Roboto", 10, QFont::Medium));
        drawerLayout->addWidget(modelButton[i]);
        connect(modelButton[i], &QtMaterialRaisedButton::pressed, [=]()
                { emit model_num(i); });
        i++;
    }
    drawerLayout->addStretch(2);
    drawerLayout->setContentsMargins(10, 10, 10, 10);
    connect(this, &MainWindow::model_num, ui->stackedWidget_2, &QStackedWidget::setCurrentIndex);
}

void MainWindow::init_form()
{
    model_select();
    init_model1();
    init_model2();
    init_model3();
}

void MainWindow::init_model1()
{
    ui->textBrowser->document()->setMaximumBlockCount(1000); // 设置textBrowser显示最大行数
    m_tabs = ui->widget;
    m_tabs->addTab("page1");
    m_tabs->addTab("page2");
    m_tabs->addTab("page3");
    connect(m_tabs, &QtMaterialTabs::currentChanged, ui->stackedWidget, &QStackedWidget::setCurrentIndex); // 选择不同的页
    // 姿态传感器部分
    m_widgetPFD = ui->widget_3; // 陀螺仪
    ui->Roll->setLabel("Roll");
    ui->Pitch->setLabel("Pitch");
    ui->Heading->setLabel("Heading");
    ui->Pressure->setLabel("Pressure");
    ui->fAccelation_X->setLabel("fAccelation_X");
    ui->fAccelation_Y->setLabel("fAccelation_Y");
    ui->fAccelation_Z->setLabel("fAccelation_Z");
    ui->fAngleSpeed_X->setLabel("fAngleSpeed_X");
    ui->fAngleSpeed_Y->setLabel("fAngleSpeed_Y");
    ui->fAngleSpeed_Z->setLabel("fAngleSpeed_Z");
    ui->fMegAmplitude_X->setLabel("fMegAmplitude_X");
    ui->fMegAmplitude_Y->setLabel("fMegAmplitude_Y");
    ui->fMegAmplitude_Z->setLabel("fMegAmplitude_Z");
    ui->fTemperature->setLabel("fTemperature");
    ui->iElapse->setLabel("iElapse");
    ui->iMegStatus->setLabel("iMegStatus");
    //   m_widgetPFD->setFlightPathMarker ( 2, 2 );
    //   m_widgetPFD->setSlipSkid      ( 2  );
    //   m_widgetPFD->setTurnRate      ( 2 / 6.0f );
    //   m_widgetPFD->setDevH          ( 2      );
    //   m_widgetPFD->setDevV          ( 2      );
    //   m_widgetPFD->setMachNo        ( 2    );
    //   m_widgetPFD->setClimbRate     ( 2 / 100.0f );
    //   m_widgetPFD->setDistance      ( 2, true );
    // 高度传感器部分
    ui->fHeight->setLabel("高度");
    ui->fConfidence->setLabel("高度可信度");
    ui->fPluseWidth->setLabel("脉宽");
    ui->iD->setLabel("脉冲编号");
    ui->fRange_Start->setLabel("起始距离");
    ui->fRange_Length->setLabel("扫描长度");
    ui->fGain->setLabel("增益");
    ui->iDataLength->setLabel("数据长度");
    ui->Altimeter->addGraph();
    ui->Altimeter->xAxis->setLabel("点数");
    ui->Altimeter->yAxis->setLabel("扫描数据");
    // 湿度计部分
    m_waterwave_1 = ui->widget_2; // 湿度计1
    m_waterwave_2 = ui->widget_4;
    m_waterwave_3 = ui->widget_5;
    m_waterwave_4 = ui->widget_6;
    // 温度计部分
    ui->thermometer1->setMinValue(0);
    ui->thermometer2->setMinValue(0);
    ui->thermometer3->setMinValue(0);
    ui->thermometer4->setMinValue(0);
    ui->thermometer1->setMaxValue(100);
    ui->thermometer2->setMaxValue(100);
    ui->thermometer3->setMaxValue(100);
    ui->thermometer4->setMaxValue(100);
    // cuntomplot部分
    // 温度部分
    ui->cuntomplot1->axisRect()->addAxis(QCPAxis::atRight);                                                              // 设置纵轴在右边
    ui->cuntomplot1->axisRect()->axis(QCPAxis::atRight, 1)->setPadding(80);                                              // 给标签留出空位
    mGraph1 = ui->cuntomplot1->addGraph(ui->cuntomplot1->xAxis, ui->cuntomplot1->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线1
    mGraph2 = ui->cuntomplot1->addGraph(ui->cuntomplot1->xAxis, ui->cuntomplot1->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线2
    mGraph3 = ui->cuntomplot1->addGraph(ui->cuntomplot1->xAxis, ui->cuntomplot1->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线2
    mGraph4 = ui->cuntomplot1->addGraph(ui->cuntomplot1->xAxis, ui->cuntomplot1->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线2
    mGraph1->setPen(QPen(Qt::GlobalColor::red));                                                                         // 设置颜色
    mGraph2->setPen(QPen(Qt::GlobalColor::blue));                                                                        // 设置颜色
    mGraph3->setPen(QPen(Qt::GlobalColor::yellow));                                                                      // 设置颜色
    mGraph4->setPen(QPen(Qt::GlobalColor::green));                                                                       // 设置颜色
    mTag1 = new AxisTag(mGraph1->valueAxis());
    mTag1->setPen(mGraph1->pen());
    mTag2 = new AxisTag(mGraph2->valueAxis());
    mTag2->setPen(mGraph2->pen());
    mTag3 = new AxisTag(mGraph3->valueAxis());
    mTag3->setPen(mGraph3->pen());
    mTag4 = new AxisTag(mGraph4->valueAxis());
    mTag4->setPen(mGraph4->pen());
    // 湿度部分
    ui->cuntomplot2->axisRect()->addAxis(QCPAxis::atRight);                                                               // 设置纵轴在右边
    ui->cuntomplot2->axisRect()->axis(QCPAxis::atRight, 1)->setPadding(80);                                               // 给标签留出空位
    mGraph01 = ui->cuntomplot2->addGraph(ui->cuntomplot2->xAxis, ui->cuntomplot2->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线1
    mGraph02 = ui->cuntomplot2->addGraph(ui->cuntomplot2->xAxis, ui->cuntomplot2->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线2
    mGraph03 = ui->cuntomplot2->addGraph(ui->cuntomplot2->xAxis, ui->cuntomplot2->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线2
    mGraph04 = ui->cuntomplot2->addGraph(ui->cuntomplot2->xAxis, ui->cuntomplot2->axisRect()->axis(QCPAxis::atRight, 1)); // 增加曲线2
    mGraph01->setPen(QPen(Qt::GlobalColor::red));                                                                         // 设置颜色
    mGraph02->setPen(QPen(Qt::GlobalColor::blue));                                                                        // 设置颜色
    mGraph03->setPen(QPen(Qt::GlobalColor::yellow));                                                                      // 设置颜色
    mGraph04->setPen(QPen(Qt::GlobalColor::green));                                                                       // 设置颜色
    mTag01 = new AxisTag(mGraph01->valueAxis());
    mTag01->setPen(mGraph01->pen());
    mTag02 = new AxisTag(mGraph02->valueAxis());
    mTag02->setPen(mGraph02->pen());
    mTag03 = new AxisTag(mGraph03->valueAxis());
    mTag03->setPen(mGraph03->pen());
    mTag04 = new AxisTag(mGraph04->valueAxis());
    mTag04->setPen(mGraph04->pen());
    // FFT波形部分
    m_datachange = new datachange();
    m_datachangeThread = new QThread();
    m_datachange->moveToThread(m_datachangeThread);                                           // 把m_datachange转移到新的线程运行
    connect(m_datachangeThread, SIGNAL(finished()), m_datachangeThread, SLOT(deleteLater())); // 关联deleteLater槽函数，这是线程安全退出的关键
    connect(m_datachangeThread, SIGNAL(finished()), m_datachange, SLOT(deleteLater()));
    connect(this, &MainWindow::creatdatachange, m_datachange, &datachange::creatchange);
    // 网络连接部分
    m_tcpThread = new QThread();  // 创建一个QThread对象
    m_tcpThread2 = new QThread(); // 创建一个QThread对象
    m_tcpclient = new tcpclient();
    m_tcpclient2 = new tcpclient2();
    m_tcpclient->moveToThread(m_tcpThread);                                     // 把m_tcpclient转移到新的线程运行
    m_tcpclient2->moveToThread(m_tcpThread2);                                   // 把m_tcpclient转移到新的线程运行
    connect(m_tcpThread, SIGNAL(finished()), m_tcpThread, SLOT(deleteLater())); // 关联deleteLater槽函数，这是线程安全退出的关键
    connect(m_tcpThread, SIGNAL(finished()), m_tcpclient, SLOT(deleteLater()));
    connect(m_tcpThread2, SIGNAL(finished()), m_tcpThread2, SLOT(deleteLater())); // 关联deleteLater槽函数，这是线程安全退出的关键
    connect(m_tcpThread2, SIGNAL(finished()), m_tcpclient2, SLOT(deleteLater()));
    ui->pushButton->setRole(Material::Role::Primary);
    ui->pushButton->setHaloVisible(false);
    ui->pushButton->setBackgroundMode(Qt::BGMode::OpaqueMode);
    ui->pushButton_CONNECT->setRole(Material::Role::Primary);
    ui->pushButton_CONNECT->setHaloVisible(false);
    ui->pushButton_CONNECT->setBackgroundMode(Qt::BGMode::OpaqueMode);
    connect(m_tcpclient, &tcpclient::recivedone, this, &MainWindow::addLogMess);
    connect(m_tcpclient, &tcpclient::getheigth, this, &MainWindow::addLogMessIn);

    connect(m_tcpclient, &tcpclient::connect_done, this, &MainWindow::m_tcpclient_connected);       // 连接完成信号槽
    connect(m_tcpclient, &tcpclient::disconnect_done, this, &MainWindow::m_tcpclient_disconnected); // 断开完成信号槽
    connect(m_tcpclient2, &tcpclient2::recivedone, this, &MainWindow::addLogMess);
    connect(m_tcpclient2, &tcpclient2::connect_done, this, &MainWindow::m_tcpclient2_connected);       // 连接完成信号槽
    connect(m_tcpclient2, &tcpclient2::disconnect_done, this, &MainWindow::m_tcpclient2_disconnected); // 断开完成信号槽
    connect(m_tcpclient2, &tcpclient2::startdatachange, m_datachange, &datachange::startchange, Qt::QueuedConnection);
    connect(this, &MainWindow::tcpcreat, m_tcpclient, &tcpclient::creattcpclient);           // 创建tcpclient信号槽
    connect(this, &MainWindow::tcpwrite, m_tcpclient, &tcpclient::write);                    // 创建tcpclient信号槽
    connect(this, &MainWindow::tcpconnect, m_tcpclient, &tcpclient::connectnet);             // tcp连接信号槽
    connect(this, &MainWindow::tcpdisconnect, m_tcpclient, &tcpclient::disconnectnet);       // tcp断开信号槽
    connect(this, &MainWindow::tcp2creat, m_tcpclient2, &tcpclient2::creattcpclient);        // 创建tcpclient2信号槽
    connect(this, &MainWindow::tcp2write, m_tcpclient2, &tcpclient2::write);                 // 创建tcpclient2信号槽
    connect(this, &MainWindow::tcp2connect, m_tcpclient2, &tcpclient2::connectnet);          // tcp2连接信号槽
    connect(this, &MainWindow::tcp2disconnect, m_tcpclient2, &tcpclient2::disconnectnet);    // tcp2断开信号槽
    connect(this, &MainWindow::setfilename, m_tcpclient2, &tcpclient2::setfilename);         // tcp2断开信号槽
    connect(this, &MainWindow::setsavefileflag, m_tcpclient2, &tcpclient2::setsavefileflag); // tcp2断开信号槽
    connect(m_tcpclient, &tcpclient::updateAltitudeDisplay, this, &MainWindow::onAltitudeUpdated);
    connect(m_tcpclient, &tcpclient::updateUTCDisplay, this, &MainWindow::onUTCUpdated);
    connect(m_tcpclient, &tcpclient::updateStateDisplay, this, &MainWindow::onStateUpdated);
    connect(m_tcpclient, &tcpclient::updateStateDisplay_Mode, this, &MainWindow::onStateUpdated_Mode);

    m_tcpThread->start();        // 开始线程
    m_tcpThread2->start();       // 开始线程2
    emit tcpcreat();             // 创建tcpclient
    emit tcp2creat();            // 创建tcpclient2
    m_datachangeThread->start(); // 开始线程
    emit creatdatachange();
    // 下发时间部分
    //    ui->pushButton_Cur_Time->setRole(Material::Role::Primary);
    //    ui->pushButton_Cur_Time->setHaloVisible(false);
    //    ui->pushButton_Cur_Time->setBackgroundMode(Qt::BGMode::OpaqueMode);
    // 采集参数部分
    //    ui->pushButton_Control_Signal->setRole(Material::Role::Primary);
    //    ui->pushButton_Control_Signal->setBackgroundMode(Qt::BGMode::OpaqueMode);
    //    ui->pushButton_Control_Signal->setHaloVisible(false);
    //    ui->pushButton_SetTVG_Gain->setRole(Material::Role::Primary);
    //    ui->pushButton_SetTVG_Gain->setBackgroundMode(Qt::BGMode::OpaqueMode);
    //    ui->pushButton_SetTVG_Gain->setHaloVisible(false);
    // 定时器部分
    timer = new QTimer(this);
    Activity = new QTimer(this);

    // connect(m_tcpclient, &tcpclient::displaySASTankStatus, this, &MainWindow::displaysomthing);
    connect(timer, &QTimer::timeout, this, &MainWindow::displaysomthing);
    connect(Activity, &QTimer::timeout, this, &MainWindow::Activity_timer);
    timer->start(200);
    Activity->start(500);
}

void MainWindow::init_model2()
{
}
void MainWindow::init_model3()
{
}
void MainWindow::Activity_timer()
{
    if (fActivity_flag == 1 && fWorken_flag == 1)
    {
        on_pushButton_Activity_clicked(true);
        usleep(700000);
    }
}
void MainWindow::displaysomthing()
{
    m_datatime = new QDateTime(QDateTime::currentDateTime());
    QString timestr = m_datatime->toString("yyyy-MM-dd  hh:mm:ss  ddd"); // 设置显示格式
    ui->statusbar->showMessage(timestr);
    // ck++;
    // on_pushButton_Activity_clicked(true);
    if (fSystemTime_flag == 1)
    {
        display_Control_Get_Time();
        fSystemTime_flag = 0;
    }
    if (fSignalType_flag_H == 1)
    {
        display_GetSignalType_H();
        fSignalType_flag_H = 0;
    }
    if (fSignalType_flag_L == 1)
    {
        display_GetSignalType_L();
        fSignalType_flag_L = 0;
    }
    if (fGain_flag == 1)
    {
        display_Get_TVG_Gain();
        fGain_flag = 0;
    }
    if (fWorkPower_flag == 1)
    {
        display_GetWorkPower();
        fWorkPower_flag = 0;
    }
    if (fTVG_flag_H == 1)
    {
        display_GetTVG_H();
        fTVG_flag_H = 0;
    }
    if (fTVG_flag_L == 1)
    {
        display_GetTVG_L();
        fTVG_flag_L = 0;
    }
    if (fWorkMode_flag == 1)
    {
        display_GetWorkMode();
        fWorkMode_flag = 0;
    }
    if (fTEMP_flag == 1)
    {
        display_GetTemp();
        fTEMP_flag = 0;
    }
    if (fHumidity_flag == 1)
    {
        display_GetHumidity();
        fHumidity_flag = 0;
    }
    if (fTVG_flag_H == 1)
    {
        display_GetTVG_H();
        fTVG_flag_H = 0;
    }
    if (fTVG_flag_L == 1)
    {
        display_GetTVG_L();
        fTVG_flag_L = 0;
    }
    if (fSASTankStatus_flag == 1)
    {
        display_GetSASTankStatus(); // 显示声纳湿端水密仓状态参数
        fSASTankStatus = 0;
    }
    if (fPressureHeight_flag == 1)
    {
        display_GetPressureHeight(); // 显示压力传感器应答参数
        fPressureHeight_flag = 0;
    }
    if (fPressureHeightEN_flag == 1)
    {
        display_GetPressureHeightEn();
        fPressureHeightEN_flag = 0;
    }
    if (fAltitudeSensor_flag == 1)
    {
        display_GetAltitudeSensor(); // 显示姿态传感器应答参数
        fAltitudeSensor_flag = 0;
    }
    if (fAltitudeSensorEN_flag == 1)
    {
        display_GetAltitudeSensorEn();
        fAltitudeSensorEN_flag = 0;
    }
    if (fSonarWorkingStatus == 1)
    {
        display_SonarWorkingStatus(); // 显示声纳工作状态应答
        fSonarWorkingStatus = 0;
    }
    if (fSoundVelocity_flag == 1)
    {
        display_GetSoundVelocity(); // 显示声速参数
        fSoundVelocity_flag = 0;
    }
    if (fAltimeter_flag == 1)
    {
        display_GetAltimeter(); // 显示高度传感器应答参数
        fAltimeter = 0;
    }
}

void MainWindow::on_action_4_triggered()
{
    m_drawer->openDrawer(); // 打开型号选择界面
}

void MainWindow::on_pushButton_clicked()
{
    if (ui->pushButton->text() == "连接")
    {
        emit tcpconnect(ui->lineEdit->text(), ui->lineEdit_2->text().toUShort());
    }
    else
    {
        emit tcpdisconnect();
    }
}

void MainWindow::addLogMess(QString mes, Qt::GlobalColor color)
{
    ui->textBrowser->moveCursor(QTextCursor::End);
    mes.append("\n");
    ui->textBrowser->setTextColor(color);
    ui->textBrowser->insertPlainText(mes);
    QTextCursor _qc = ui->textBrowser->textCursor();
    _qc.movePosition(QTextCursor::End);
    ui->textBrowser->setTextCursor(_qc);
}
void MainWindow::addLogMessIn(int valuse, Qt::GlobalColor color)
{
    // Convert integer to hexadecimal string
    QString hexString = QString::number(valuse, 16).toUpper(); // Convert to uppercase hex string

    // Append newline to ensure new log appears on a new line
    hexString.append("\n");

    // Move cursor to the end
    ui->textBrowser->moveCursor(QTextCursor::End);

    // Set text color
    ui->textBrowser->setTextColor(color);

    // Insert formatted text into textBrowser
    ui->textBrowser->insertPlainText(hexString);

    // Move cursor to the end again to ensure it remains at the end after insertion
    QTextCursor _qc = ui->textBrowser->textCursor();
    _qc.movePosition(QTextCursor::End);
    ui->textBrowser->setTextCursor(_qc);
}
// 系统时间
void MainWindow::receive_Control_Cur_Time()
{
    QDateTime current_datetime = QDateTime::currentDateTime();
    long long int timeStr = current_datetime.toMSecsSinceEpoch();
    memset(&m_pack_Control_To_PC_SystemTime, 0, sizeof(m_pack_Control_To_PC_SystemTime));
    m_pack_Control_To_PC_SystemTime.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_SystemTime.Device_Address = 0x00;
    m_pack_Control_To_PC_SystemTime.Opreation = 0x82;
    m_pack_Control_To_PC_SystemTime.KeyWord = 0x0101;
    m_pack_Control_To_PC_SystemTime.DataLength = sizeof(m_pack_Control_To_PC_SystemTime.systime);
    m_pack_Control_To_PC_SystemTime.systime = timeStr;
    m_pack_Control_To_PC_SystemTime.Check_Sum = 0;
    m_pack_Control_To_PC_SystemTime.Massage_Tail = 0xff0d;
}
void MainWindow::receive_Control_Get_Time()
{
    memset(&m_pack_Control_To_PC_SystemTime, 0, sizeof(m_pack_Control_To_PC_SystemTime));
    m_pack_Control_To_PC_SystemTime.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_SystemTime.Device_Address = 0x00;
    m_pack_Control_To_PC_SystemTime.Opreation = 0x80;
    m_pack_Control_To_PC_SystemTime.KeyWord = 0x0101;
    m_pack_Control_To_PC_SystemTime.DataLength = sizeof(m_pack_Control_To_PC_SystemTime.systime);
    m_pack_Control_To_PC_SystemTime.Check_Sum = 0;
    m_pack_Control_To_PC_SystemTime.Massage_Tail = 0xff0d;
}

// 信号类型
void MainWindow::receive_Control_Set_SignalType_H()
{ // todo
    memset(&m_pack_Control_To_SignalType_H, 0, sizeof(m_pack_Control_To_SignalType_H));
    m_pack_Control_To_SignalType_H.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_SignalType_H.Device_Address = 0x01;
    m_pack_Control_To_SignalType_H.Opreation = 0x82;
    m_pack_Control_To_SignalType_H.KeyWord = 0x0102;
    m_pack_Control_To_SignalType_H.DataLength = sizeof(m_pack_Control_To_SignalType_H.signaltype_H);
    m_pack_Control_To_SignalType_H.signaltype_H = static_cast<unsigned short>(ui->comboBox_SignalType->currentIndex()); // 前信号源信号形式
    m_pack_Control_To_SignalType_H.Check_Sum = 0;
    m_pack_Control_To_SignalType_H.Massage_Tail = 0xff0d;
}
void MainWindow::receive_Control_Set_SignalType_L()
{ // todo
    memset(&m_pack_Control_To_SignalType_L, 0, sizeof(m_pack_Control_To_SignalType_L));
    m_pack_Control_To_SignalType_L.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_SignalType_L.Device_Address = 0x02;
    m_pack_Control_To_SignalType_L.Opreation = 0x82;
    m_pack_Control_To_SignalType_L.KeyWord = 0x0102;
    m_pack_Control_To_SignalType_L.DataLength = sizeof(m_pack_Control_To_SignalType_L.signaltype_L);
    m_pack_Control_To_SignalType_L.signaltype_L = static_cast<unsigned short>(ui->comboBox_SignalType_2->currentIndex()); // 前信号源信号形式
    m_pack_Control_To_SignalType_L.Check_Sum = 0;
    m_pack_Control_To_SignalType_L.Massage_Tail = 0xff0d;
}

void MainWindow::receive_Control_Get_SignalType_H()
{
    memset(&m_pack_Control_To_SignalType_H, 0, sizeof(m_pack_Control_To_SignalType_H));
    m_pack_Control_To_SignalType_H.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_SignalType_H.Device_Address = 0x01;
    m_pack_Control_To_SignalType_H.Opreation = 0x80;
    m_pack_Control_To_SignalType_H.KeyWord = 0x0102;
    m_pack_Control_To_SignalType_H.DataLength = sizeof(m_pack_Control_To_SignalType_H.signaltype_H);
    m_pack_Control_To_SignalType_H.Check_Sum = 0;
    m_pack_Control_To_SignalType_H.Massage_Tail = 0xff0d;
}

void MainWindow::receive_Control_Get_SignalType_L()
{
    memset(&m_pack_Control_To_SignalType_L, 0, sizeof(m_pack_Control_To_SignalType_L));
    m_pack_Control_To_SignalType_L.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_SignalType_L.Device_Address = 0x02;
    m_pack_Control_To_SignalType_L.Opreation = 0x80;
    m_pack_Control_To_SignalType_L.KeyWord = 0x0102;
    m_pack_Control_To_SignalType_L.DataLength = sizeof(m_pack_Control_To_SignalType_L.signaltype_L);
    m_pack_Control_To_SignalType_L.Check_Sum = 0;
    m_pack_Control_To_SignalType_L.Massage_Tail = 0xff0d;
}
// TVG增益值
void MainWindow::receive_Set_TVG_Gain()
{
    memset(&m_pack_PC_To_Control_TVG_Gain, 0, sizeof(pack_PC_To_Control_TVG_Gain));
    m_pack_PC_To_Control_TVG_Gain.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TVG_Gain.Device_Address = 0x02;
    m_pack_PC_To_Control_TVG_Gain.Opreation = 0x82;
    m_pack_PC_To_Control_TVG_Gain.KeyWord = 0x0104;
    m_pack_PC_To_Control_TVG_Gain.DataLength = sizeof(m_pack_PC_To_Control_TVG_Gain.gain);
    m_pack_PC_To_Control_TVG_Gain.gain = ui->lineEdit_TVG_Gain->text().toInt();
    m_pack_PC_To_Control_TVG_Gain.Check_Sum = 0;
    m_pack_PC_To_Control_TVG_Gain.Massage_Tail = 0xff0d;
}
void MainWindow::receive_Get_TVG_Gain()
{
    memset(&m_pack_PC_To_Control_TVG_Gain, 0, sizeof(pack_PC_To_Control_TVG_Gain));
    m_pack_PC_To_Control_TVG_Gain.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TVG_Gain.Device_Address = 0x02;
    m_pack_PC_To_Control_TVG_Gain.Opreation = 0x80;
    m_pack_PC_To_Control_TVG_Gain.KeyWord = 0x0104;
    m_pack_PC_To_Control_TVG_Gain.DataLength = sizeof(m_pack_PC_To_Control_TVG_Gain.gain);
    m_pack_PC_To_Control_TVG_Gain.gain = 0;
    m_pack_PC_To_Control_TVG_Gain.Check_Sum = 0;
    m_pack_PC_To_Control_TVG_Gain.Massage_Tail = 0xff0d;
}
// 发射功率
void MainWindow::receive_SetWorkPower()
{
    memset(&m_pack_PC_To_Control_WorkPower, 0, sizeof(m_pack_PC_To_Control_WorkPower));
    m_pack_PC_To_Control_WorkPower.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_WorkPower.Device_Address = 0x03;
    m_pack_PC_To_Control_WorkPower.Opreation = 0x82;
    m_pack_PC_To_Control_WorkPower.KeyWord = 0x0105;
    m_pack_PC_To_Control_WorkPower.DataLength = sizeof(m_pack_PC_To_Control_WorkPower.work_power);
    m_pack_PC_To_Control_WorkPower.work_power = static_cast<unsigned char>(ui->comboBox_WorkPower->currentIndex());
    m_pack_PC_To_Control_WorkPower.Check_Sum = 0;
    m_pack_PC_To_Control_WorkPower.Massage_Tail = 0xff0d;
}
void MainWindow::receive_GetWorkPower()
{
    memset(&m_pack_PC_To_Control_WorkPower, 0, sizeof(m_pack_PC_To_Control_WorkPower));
    m_pack_PC_To_Control_WorkPower.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_WorkPower.Device_Address = 0x03;
    m_pack_PC_To_Control_WorkPower.Opreation = 0x80;
    m_pack_PC_To_Control_WorkPower.KeyWord = 0x0105;
    m_pack_PC_To_Control_WorkPower.DataLength = sizeof(m_pack_PC_To_Control_WorkPower.work_power);
    m_pack_PC_To_Control_WorkPower.Check_Sum = 0;
    m_pack_PC_To_Control_WorkPower.Massage_Tail = 0xff0d;
}
// 时间增益控制参数
void MainWindow::receive_SetTVG_H()
{ // todo
    memset(&m_pack_PC_To_Control_TVG_H, 0, sizeof(m_pack_PC_To_Control_TVG_H));
    m_pack_PC_To_Control_TVG_H.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TVG_H.Device_Address = 0x01;
    m_pack_PC_To_Control_TVG_H.Opreation = 0x82;
    m_pack_PC_To_Control_TVG_H.KeyWord = 0x0106;
    m_pack_PC_To_Control_TVG_H.DataLength = sizeof(m_pack_PC_To_Control_TVG_H.m_TVG_H);
    m_pack_PC_To_Control_TVG_H.m_TVG_H.TVG_Alpha = ui->comboBox_TVG_Alpha->currentText().toFloat(); // 时间增益控制参数α
    m_pack_PC_To_Control_TVG_H.m_TVG_H.TVG_Beta = ui->comboBox_TVG_Beta->currentText().toFloat();   // 时间增益控制参数β
    m_pack_PC_To_Control_TVG_H.m_TVG_H.TVG_Gamma = ui->comboBox_TVG_Gamma->currentText().toFloat(); // 时间增益控制参数γ
    m_pack_PC_To_Control_TVG_H.Check_Sum = 0;
    m_pack_PC_To_Control_TVG_H.Massage_Tail = 0xff0d;
}

void MainWindow::receive_SetTVG_L()
{ // todo
    memset(&m_pack_PC_To_Control_TVG_L, 0, sizeof(m_pack_PC_To_Control_TVG_L));
    m_pack_PC_To_Control_TVG_L.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TVG_L.Device_Address = 0x02;
    m_pack_PC_To_Control_TVG_L.Opreation = 0x82;
    m_pack_PC_To_Control_TVG_L.KeyWord = 0x0106;
    m_pack_PC_To_Control_TVG_L.DataLength = sizeof(m_pack_PC_To_Control_TVG_L.m_TVG_L);
    m_pack_PC_To_Control_TVG_L.m_TVG_L.TVG_Alpha = ui->comboBox_TVG_Alpha_2->currentText().toFloat(); // 时间增益控制参数α
    m_pack_PC_To_Control_TVG_L.m_TVG_L.TVG_Beta = ui->comboBox_TVG_Beta_2->currentText().toFloat();   // 时间增益控制参数β
    m_pack_PC_To_Control_TVG_L.m_TVG_L.TVG_Gamma = ui->comboBox_TVG_Gamma_2->currentText().toFloat(); // 时间增益控制参数γ
    m_pack_PC_To_Control_TVG_L.Check_Sum = 0;
    m_pack_PC_To_Control_TVG_L.Massage_Tail = 0xff0d;
}

void MainWindow::receive_GetTVG_H()
{
    memset(&m_pack_PC_To_Control_TVG_H, 0, sizeof(m_pack_PC_To_Control_TVG_H));
    m_pack_PC_To_Control_TVG_H.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TVG_H.Device_Address = 0x01;
    m_pack_PC_To_Control_TVG_H.Opreation = 0x80;
    m_pack_PC_To_Control_TVG_H.KeyWord = 0x0106;
    m_pack_PC_To_Control_TVG_H.DataLength = sizeof(m_pack_PC_To_Control_TVG_H.m_TVG_H);
    m_pack_PC_To_Control_TVG_H.Check_Sum = 0;
    m_pack_PC_To_Control_TVG_H.Massage_Tail = 0xff0d;
}
void MainWindow::receive_GetTVG_L()
{
    memset(&m_pack_PC_To_Control_TVG_L, 0, sizeof(m_pack_PC_To_Control_TVG_L));
    m_pack_PC_To_Control_TVG_L.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TVG_L.Device_Address = 0x02;
    m_pack_PC_To_Control_TVG_L.Opreation = 0x80;
    m_pack_PC_To_Control_TVG_L.KeyWord = 0x0106;
    m_pack_PC_To_Control_TVG_L.DataLength = sizeof(m_pack_PC_To_Control_TVG_L.m_TVG_L);
    m_pack_PC_To_Control_TVG_L.Check_Sum = 0;
    m_pack_PC_To_Control_TVG_L.Massage_Tail = 0xff0d;
}
// 工作方式
void MainWindow::receive_SetWorkMode()
{
    memset(&m_pack_PC_To_Control_WorkMode, 0, sizeof(m_pack_PC_To_Control_WorkMode));
    m_pack_PC_To_Control_WorkMode.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_WorkMode.Device_Address = 0x05;
    m_pack_PC_To_Control_WorkMode.Opreation = 0x82;
    m_pack_PC_To_Control_WorkMode.KeyWord = 0x0107;
    m_pack_PC_To_Control_WorkMode.DataLength = sizeof(m_pack_PC_To_Control_WorkMode.workmode);
    m_pack_PC_To_Control_WorkMode.workmode = static_cast<unsigned char>(ui->comboBox_Workmode->currentIndex());
    m_pack_PC_To_Control_WorkMode.Check_Sum = 0;
    m_pack_PC_To_Control_WorkMode.Massage_Tail = 0xff0d;
}
void MainWindow::receive_GetWorkMode()
{
    memset(&m_pack_PC_To_Control_WorkMode, 0, sizeof(m_pack_PC_To_Control_WorkMode));
    m_pack_PC_To_Control_WorkMode.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_WorkMode.Device_Address = 0x05;
    m_pack_PC_To_Control_WorkMode.Opreation = 0x80;
    m_pack_PC_To_Control_WorkMode.KeyWord = 0x0107;
    m_pack_PC_To_Control_WorkMode.DataLength = sizeof(m_pack_PC_To_Control_WorkMode.workmode);
    m_pack_PC_To_Control_WorkMode.Check_Sum = 0;
    m_pack_PC_To_Control_WorkMode.Massage_Tail = 0xff0d;
}

void MainWindow::receive_GetTEMP()
{
    memset(&m_pack_Control_To_PC_TEMP, 0, sizeof(m_pack_Control_To_PC_TEMP));
    m_pack_Control_To_PC_TEMP.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_TEMP.Device_Address = 0x06;
    m_pack_Control_To_PC_TEMP.Opreation = 0x80;
    m_pack_Control_To_PC_TEMP.KeyWord = 0x0150;
    m_pack_Control_To_PC_TEMP.DataLength = sizeof(m_pack_Control_To_PC_TEMP.m_Temp_Data);
    m_pack_Control_To_PC_TEMP.Check_Sum = 0;
    m_pack_Control_To_PC_TEMP.Massage_Tail = 0xff0d;
}
void MainWindow::receive_GetHumidity()
{
    memset(&m_pack_Control_To_PC_Humidity, 0, sizeof(m_pack_Control_To_PC_Humidity));
    m_pack_Control_To_PC_Humidity.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_Humidity.Device_Address = 0x07;
    m_pack_Control_To_PC_Humidity.Opreation = 0x80;
    m_pack_Control_To_PC_Humidity.KeyWord = 0x0151;
    m_pack_Control_To_PC_Humidity.DataLength = sizeof(m_pack_Control_To_PC_Humidity.m_Humidity_Data);
    m_pack_Control_To_PC_Humidity.Check_Sum = 0;
    m_pack_Control_To_PC_Humidity.Massage_Tail = 0xff0d;
}
void MainWindow::receive_GetSASTankStatus()
{
    memset(&m_pack_Control_To_PC_SASTankStatus, 0, sizeof(m_pack_Control_To_PC_SASTankStatus));
    m_pack_Control_To_PC_SASTankStatus.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_SASTankStatus.Device_Address = 0x08;
    m_pack_Control_To_PC_SASTankStatus.Opreation = 0x80;
    m_pack_Control_To_PC_SASTankStatus.KeyWord = 0x0152;
    m_pack_Control_To_PC_SASTankStatus.DataLength = sizeof(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus);
    m_pack_Control_To_PC_SASTankStatus.Check_Sum = 0;
    m_pack_Control_To_PC_SASTankStatus.Massage_Tail = 0xff0d;
}
void MainWindow::receive_GetPressureHeight()
{
    memset(&m_pack_Control_To_PC_PressureHeight, 0, sizeof(m_pack_Control_To_PC_PressureHeight));
    m_pack_Control_To_PC_PressureHeight.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_PressureHeight.Device_Address = 0x09;
    m_pack_Control_To_PC_PressureHeight.Opreation = 0x80;
    m_pack_Control_To_PC_PressureHeight.KeyWord = 0x0153;
    m_pack_Control_To_PC_PressureHeight.DataLength = sizeof(m_pack_Control_To_PC_PressureHeight.m_PressureHeight);
    m_pack_Control_To_PC_PressureHeight.Check_Sum = 0;
    m_pack_Control_To_PC_PressureHeight.Massage_Tail = 0xff0d;
}
void MainWindow::receive_SetPressureHeightEn()
{
    if (m_tcpclient->conectflag == true)
    {
        m_pack_PC_To_Control_PressureHeight_EN.Massage_Header = 0xa55ab55b;
        m_pack_PC_To_Control_PressureHeight_EN.Device_Address = 0x06;
        m_pack_PC_To_Control_PressureHeight_EN.Opreation = 0x82;
        m_pack_PC_To_Control_PressureHeight_EN.KeyWord = 0x0154;
        m_pack_PC_To_Control_PressureHeight_EN.DataLength = sizeof(m_pack_PC_To_Control_PressureHeight_EN.PressureHeight_EN);
        m_pack_PC_To_Control_PressureHeight_EN.Check_Sum = 0;
        m_pack_PC_To_Control_PressureHeight_EN.Massage_Tail = 0xff0d;
        emit tcpwrite((char *)&m_pack_PC_To_Control_PressureHeight_EN, sizeof(m_pack_PC_To_Control_PressureHeight_EN));
        addLogMess("深度开关下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::receive_GetPressureHeightEn()
{
    if (m_tcpclient->conectflag == true)
    {
        memset(&m_pack_PC_To_Control_PressureHeight_EN, 0, sizeof(m_pack_PC_To_Control_PressureHeight_EN));
        m_pack_PC_To_Control_PressureHeight_EN.Massage_Header = 0xa55ab55b;
        m_pack_PC_To_Control_PressureHeight_EN.Device_Address = 0x06;
        m_pack_PC_To_Control_PressureHeight_EN.Opreation = 0x80;
        m_pack_PC_To_Control_PressureHeight_EN.KeyWord = 0x0154;
        m_pack_PC_To_Control_PressureHeight_EN.DataLength = sizeof(m_pack_PC_To_Control_PressureHeight_EN.PressureHeight_EN);
        m_pack_PC_To_Control_PressureHeight_EN.Check_Sum = 0;
        m_pack_PC_To_Control_PressureHeight_EN.Massage_Tail = 0xff0d;
        emit tcpwrite((char *)&m_pack_PC_To_Control_PressureHeight_EN, sizeof(m_pack_PC_To_Control_PressureHeight_EN));
        addLogMess("获取深度开关状态下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::receive_GetAltitudeSensor()
{
    memset(&m_pack_Control_To_PC_AltitudeSensor, 0, sizeof(m_pack_Control_To_PC_AltitudeSensor));
    m_pack_Control_To_PC_AltitudeSensor.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_AltitudeSensor.Device_Address = 0x06;
    m_pack_Control_To_PC_AltitudeSensor.Opreation = 0x80;
    m_pack_Control_To_PC_AltitudeSensor.KeyWord = 0x0155;
    m_pack_Control_To_PC_AltitudeSensor.DataLength = sizeof(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor);
    m_pack_Control_To_PC_AltitudeSensor.Check_Sum = 0;
    m_pack_Control_To_PC_AltitudeSensor.Massage_Tail = 0xff0d;
}
void MainWindow::receive_SetAltitudeSensorEn()
{
    if (m_tcpclient->conectflag == true)
    {
        m_pack_PC_To_Control_AltitudeSensor_EN.Massage_Header = 0xa55ab55b;
        m_pack_PC_To_Control_AltitudeSensor_EN.Device_Address = 0x06;
        m_pack_PC_To_Control_AltitudeSensor_EN.Opreation = 0x82;
        m_pack_PC_To_Control_AltitudeSensor_EN.KeyWord = 0x0156;
        m_pack_PC_To_Control_AltitudeSensor_EN.DataLength = sizeof(m_pack_PC_To_Control_AltitudeSensor_EN.AltitudeSensor_EN);
        m_pack_PC_To_Control_AltitudeSensor_EN.Check_Sum = 0;
        m_pack_PC_To_Control_AltitudeSensor_EN.Massage_Tail = 0xff0d;
        emit tcpwrite((char *)&m_pack_PC_To_Control_AltitudeSensor_EN, sizeof(m_pack_PC_To_Control_AltitudeSensor_EN));
        addLogMess("姿态开关下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::receive_GetAltitudeSensorEn()
{
    if (m_tcpclient->conectflag == true)
    {
        m_pack_PC_To_Control_AltitudeSensor_EN.Massage_Header = 0xa55ab55b;
        m_pack_PC_To_Control_AltitudeSensor_EN.Device_Address = 0x06;
        m_pack_PC_To_Control_AltitudeSensor_EN.Opreation = 0x80;
        m_pack_PC_To_Control_AltitudeSensor_EN.KeyWord = 0x0156;
        m_pack_PC_To_Control_AltitudeSensor_EN.DataLength = sizeof(m_pack_PC_To_Control_AltitudeSensor_EN.AltitudeSensor_EN);
        m_pack_PC_To_Control_AltitudeSensor_EN.Check_Sum = 0;
        m_pack_PC_To_Control_AltitudeSensor_EN.Massage_Tail = 0xff0d;
        emit tcpwrite((char *)&m_pack_PC_To_Control_AltitudeSensor_EN, sizeof(m_pack_PC_To_Control_AltitudeSensor_EN));
        addLogMess("获取姿态开关状态下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::receive_SetSoundVelocity()
{
    if (m_tcpclient->conectflag == true)
    {
        m_pack_PC_To_Control_SoundVelocity.Massage_Header = 0xa55ab55b;
        m_pack_PC_To_Control_SoundVelocity.Device_Address = 0x06;
        m_pack_PC_To_Control_SoundVelocity.Opreation = 0x82;
        m_pack_PC_To_Control_SoundVelocity.KeyWord = 0x0157;
        m_pack_PC_To_Control_SoundVelocity.DataLength = sizeof(m_pack_PC_To_Control_SoundVelocity.sound_velocity);
        m_pack_PC_To_Control_SoundVelocity.Check_Sum = 0;
        m_pack_PC_To_Control_SoundVelocity.Massage_Tail = 0xff0d;
        emit tcpwrite((char *)&m_pack_PC_To_Control_SoundVelocity, sizeof(m_pack_PC_To_Control_SoundVelocity));
        addLogMess("声速下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::receive_GetSoundVelocity()
{
    if (m_tcpclient->conectflag == true)
    {
        m_pack_PC_To_Control_SoundVelocity.Massage_Header = 0xa55ab55b;
        m_pack_PC_To_Control_SoundVelocity.Device_Address = 0x06;
        m_pack_PC_To_Control_SoundVelocity.Opreation = 0x80;
        m_pack_PC_To_Control_SoundVelocity.KeyWord = 0x0157;
        m_pack_PC_To_Control_SoundVelocity.DataLength = sizeof(m_pack_PC_To_Control_SoundVelocity.sound_velocity);
        m_pack_PC_To_Control_SoundVelocity.Check_Sum = 0;
        m_pack_PC_To_Control_SoundVelocity.Massage_Tail = 0xff0d;
        emit tcpwrite((char *)&m_pack_PC_To_Control_SoundVelocity, sizeof(m_pack_PC_To_Control_SoundVelocity));
        addLogMess("获取声速下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::receive_GetAltimeter()
{
    memset(&m_pack_Control_To_PC_Altimeter, 0, sizeof(m_pack_Control_To_PC_Altimeter));
    m_pack_Control_To_PC_Altimeter.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_Altimeter.Device_Address = 0x06;
    m_pack_Control_To_PC_Altimeter.Opreation = 0x80;
    m_pack_Control_To_PC_Altimeter.KeyWord = 0x0180;
    m_pack_Control_To_PC_Altimeter.DataLength = sizeof(m_pack_Control_To_PC_Altimeter.data);
    m_pack_Control_To_PC_Altimeter.Check_Sum = 0;
    m_pack_Control_To_PC_Altimeter.Massage_Tail = 0xff0d;
}
void MainWindow::receive_Control_Signal_H()
{
    memset(&m_pack_PC_To_Control_Signal_H, 0, sizeof(m_pack_PC_To_Control_Signal_H));
    m_pack_PC_To_Control_Signal_H.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_Signal_H.Device_Address = 0x01;
    m_pack_PC_To_Control_Signal_H.Opreation = 0x82;
    m_pack_PC_To_Control_Signal_H.KeyWord = 0x1102;
    m_pack_PC_To_Control_Signal_H.DataLength = sizeof(m_pack_PC_To_Control_Signal_H.m_Control_Signal_H);
    // todo
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.CarrierFrquncy = ui->comboBox_H_CarrierFrquncy->currentText().toFloat(); // 信号源中心频率
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.BandWidth = ui->comboBox_H_BandWidth->currentText().toFloat();           // 信号源信号带宽
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.PulseWidth = ui->comboBox_H_PulseWidth->currentText().toFloat();         // 信号源信号脉宽
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.rFs = ui->comboBox_rFS->currentText().toFloat();                         // 采样率
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.PRI = ui->comboBox_PRI->currentText().toFloat();                         // 脉冲重复周期
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.rMin = ui->comboBox_rMin->currentText().toFloat();                       // 最小采样距离
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.rMax = ui->comboBox_rMax->currentText().toFloat();                       // 最大采样距离
    m_pack_PC_To_Control_Signal_H.m_Control_Signal_H.fNumOfReceiver = 40;
    m_pack_PC_To_Control_Signal_H.Check_Sum = 0;
    m_pack_PC_To_Control_Signal_H.Massage_Tail = 0xff0d;
}

void MainWindow::receive_Control_Signal_L()
{
    memset(&m_pack_PC_To_Control_Signal_L, 0, sizeof(m_pack_PC_To_Control_Signal_L));
    m_pack_PC_To_Control_Signal_L.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_Signal_L.Device_Address = 0x02;
    m_pack_PC_To_Control_Signal_L.Opreation = 0x82;
    m_pack_PC_To_Control_Signal_L.KeyWord = 0x1102;
    m_pack_PC_To_Control_Signal_L.DataLength = sizeof(m_pack_PC_To_Control_Signal_L.m_Control_Signal_L);
    // todo
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.CarrierFrquncy = ui->comboBox_H_CarrierFrquncy_2->currentText().toFloat(); // 信号源中心频率
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.BandWidth = ui->comboBox_H_BandWidth_2->currentText().toFloat();           // 信号源信号带宽
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.PulseWidth = ui->comboBox_H_PulseWidth_2->currentText().toFloat();         // 信号源信号脉宽
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.rFs = ui->comboBox_rFS->currentText().toFloat();                           // 采样率
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.PRI = ui->comboBox_PRI->currentText().toFloat();                           // 脉冲重复周期
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.rMin = ui->comboBox_rMin->currentText().toFloat();                         // 最小采样距离
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.rMax = ui->comboBox_rMax->currentText().toFloat();                         // 最大采样距离
    m_pack_PC_To_Control_Signal_L.m_Control_Signal_L.fNumOfReceiver = 40;

    m_pack_PC_To_Control_Signal_L.Check_Sum = 0;
    m_pack_PC_To_Control_Signal_L.Massage_Tail = 0xff0d;
}

void MainWindow::receive_LSnoar()
{
    memset(&m_pack_PC_To_Control_L_Sonar, 0, sizeof(m_pack_PC_To_Control_L_Sonar));
    m_pack_PC_To_Control_L_Sonar.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_L_Sonar.Device_Address = 0x05;
    m_pack_PC_To_Control_L_Sonar.Opreation = 0x82;
    m_pack_PC_To_Control_L_Sonar.KeyWord = 0x1113;
    m_pack_PC_To_Control_L_Sonar.DataLength = sizeof(m_pack_PC_To_Control_L_Sonar.sonar);
    // todo
QString text = ui->lineEdit_Work_Snoar->text();// 假设从 UI 文本框读取字符串
    bool ok;
    int str = text.toInt(&ok, 2); // 将字符串按二进制转换为整数

    if (ok && str >= 0 && str <= 0x3F) // 检查转换是否成功，并且值在有效范围内
    {
        m_pack_PC_To_Control_L_Sonar.sonar = str; // 直接赋值，因为二进制值已经对应16进制
    }
    else
    {
        // 处理无效输入，例如输入的不是有效的二进制字符串
        m_pack_PC_To_Control_L_Sonar.sonar = 0x00; // 或者根据需要设置默认值
    }

    //    m_pack_PC_To_Control_L_Sonar.sonar = text.toInt();
    m_pack_PC_To_Control_L_Sonar.Check_Sum = 0;
    m_pack_PC_To_Control_L_Sonar.Massage_Tail = 0xff0d;
}
void MainWindow::receive_RSnoar()
{
    memset(&m_pack_PC_To_Control_TrigerMode, 0, sizeof(m_pack_PC_To_Control_TrigerMode));
    m_pack_PC_To_Control_TrigerMode.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_TrigerMode.Device_Address = 0x05;
    m_pack_PC_To_Control_TrigerMode.Opreation = 0x82;
    m_pack_PC_To_Control_TrigerMode.KeyWord = 0x0110;
    m_pack_PC_To_Control_TrigerMode.DataLength = sizeof(m_pack_PC_To_Control_TrigerMode.TrigerMode);
    m_pack_PC_To_Control_TrigerMode.TrigerMode = static_cast<unsigned char>(ui->comboBox_R_Sonar->currentIndex());
    m_pack_PC_To_Control_TrigerMode.Check_Sum = 0;
    m_pack_PC_To_Control_TrigerMode.Massage_Tail = 0xff0d;
}
void MainWindow::receive_infromtion()
{
    memset(&m_Device_Information, 0, sizeof(m_Device_Information));
    m_Device_Information.Massage_Header = 0xa55ab55b;
    m_Device_Information.Device_Address = 0x05;
    m_Device_Information.Opreation = 0x80;
    m_Device_Information.KeyWord = 0x0901;
    m_Device_Information.DataLength = sizeof(m_Device_Information);
    // m_Device_Information.sonar = static_cast<unsigned char>(ui->comboBox_R_Sonar->currentIndex());
    m_Device_Information.Check_Sum = 0;
    m_Device_Information.Massage_Tail = 0xff0d;
}
void MainWindow::receive_Voltage_And_Current()
{
    memset(&m_Voltage_And_Current, 0, sizeof(m_Voltage_And_Current));
    m_Voltage_And_Current.Massage_Header = 0xa55ab55b;
    m_Voltage_And_Current.Device_Address = 0x05;
    m_Voltage_And_Current.Opreation = 0x80;
    m_Voltage_And_Current.KeyWord = 0x015C;
    m_Voltage_And_Current.DataLength = sizeof(m_Voltage_And_Current);
    // m_Device_Information.sonar = static_cast<unsigned char>(ui->comboBox_R_Sonar->currentIndex());
    m_Voltage_And_Current.Check_Sum = 0;
    m_Voltage_And_Current.Massage_Tail = 0xff0d;
}
void MainWindow::receive_Activity()
{
    memset(&m_pack_PC_To_Control_Activity, 0, sizeof(m_pack_PC_To_Control_Activity));
    m_pack_PC_To_Control_Activity.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_Activity.Device_Address = 0x05;
    m_pack_PC_To_Control_Activity.Opreation = 0x80;
    m_pack_PC_To_Control_Activity.KeyWord = 0x0109;
    m_pack_PC_To_Control_Activity.DataLength = sizeof(m_pack_PC_To_Control_Activity);
    // m_Device_Information.sonar = static_cast<unsigned char>(ui->comboBox_R_Sonar->currentIndex());
    m_pack_PC_To_Control_Activity.Check_Sum = 0;
    m_pack_PC_To_Control_Activity.Massage_Tail = 0xff0d;
}
/**************************显示部分******************************/
// 获取系统时间
void MainWindow::display_Control_Get_Time()
{
    QString Control_Get_Time_result;
    QDateTime Timedata;
    Timedata.setTime_t(m_pack_Control_To_PC_SystemTime.systime);
    Control_Get_Time_result = Timedata.toString("yyyy-MM-dd hh:mm:ss");
    ui->textBrowser->insertPlainText(Control_Get_Time_result);
}
// 获取信号类型
void MainWindow::display_GetSignalType_H()
{
    QString signaltype_result;
    signaltype_result.sprintf("获取的高频信号类型为:%d", m_pack_Control_To_SignalType_H.signaltype_H);
    ui->textBrowser->insertPlainText(signaltype_result);
}
void MainWindow::display_GetSignalType_L()
{
    QString signaltype_result;
    signaltype_result.sprintf("获取的低频信号类型为:%d", m_pack_Control_To_SignalType_L.signaltype_L);
    ui->textBrowser->insertPlainText(signaltype_result);
}
// 获取Gain增益
void MainWindow::display_Get_TVG_Gain()
{
    QString Get_TVG_Gain_result;
    Get_TVG_Gain_result.sprintf("获取的Gain增益为:%d", m_pack_PC_To_Control_TVG_Gain.gain);
    ui->textBrowser->insertPlainText(Get_TVG_Gain_result);
}
// 获取发射功率
void MainWindow::display_GetWorkPower()
{
    QString GetWorkPowe_result;
    GetWorkPowe_result.sprintf("获取的发射功率为:%d", m_pack_PC_To_Control_WorkPower.work_power);
    ui->textBrowser->insertPlainText(GetWorkPowe_result);
}
// 获取TVG值
void MainWindow::display_GetTVG_H()
{
    QString GetTVG_result;
    GetTVG_result.sprintf("获取的TVG值为:A:%f B:%f,G:%f", m_pack_PC_To_Control_TVG_H.m_TVG_H.TVG_Alpha, m_pack_PC_To_Control_TVG_H.m_TVG_H.TVG_Beta, m_pack_PC_To_Control_TVG_H.m_TVG_H.TVG_Gamma);
    ui->textBrowser->insertPlainText(GetTVG_result);
}
void MainWindow::display_GetTVG_L()
{
    QString GetTVG_result;
    GetTVG_result.sprintf("获取的TVG值为:A:%f B:%f,G:%f", m_pack_PC_To_Control_TVG_L.m_TVG_L.TVG_Alpha, m_pack_PC_To_Control_TVG_L.m_TVG_L.TVG_Beta, m_pack_PC_To_Control_TVG_L.m_TVG_L.TVG_Gamma);
    ui->textBrowser->insertPlainText(GetTVG_result);
}

// 获取工作方式
void MainWindow::display_GetWorkMode()
{
    QString GetWorkMode_result;
    GetWorkMode_result.sprintf("获取的工作方式为:%d", m_pack_PC_To_Control_WorkMode.workmode);
    ui->textBrowser->insertPlainText(GetWorkMode_result);
}
// 获取温度
void MainWindow::display_GetTemp()
{
    qDebug() << "Temperature_one:%f" << m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_one;
    ui->thermometer1->setValue(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_one);    // 温度1
    ui->thermometer2->setValue(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_second); // 温度2
    ui->thermometer3->setValue(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_Three);  // 温度3
    // 温度图表显示
    mGraph1->addData(mGraph1->dataCount(), m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_one); // 温度1
    mGraph2->addData(mGraph2->dataCount(), m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_second);
    mGraph3->addData(mGraph3->dataCount(), m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_Three);
    ui->cuntomplot1->xAxis->rescale();
    mGraph1->rescaleValueAxis(true, true);
    mGraph2->rescaleValueAxis(true, true);
    mGraph3->rescaleValueAxis(true, true);
    mGraph4->rescaleValueAxis(true, true);
    ui->cuntomplot1->xAxis->setRange(ui->cuntomplot1->xAxis->range().upper, 10, Qt::AlignRight); // 设置显示的点数
    mTag1->updatePosition(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_one);
    mTag2->updatePosition(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_second);
    mTag3->updatePosition(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_Three);
    //        mTag4->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[3]);
    mTag1->setText(QString("温度1:%1").arg(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_one));
    mTag2->setText(QString("温度2:%1").arg(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_second));
    mTag3->setText(QString("温度3:%1").arg(m_pack_Control_To_PC_TEMP.m_Temp_Data.Temperature_Three));
    //        mTag4->setText(QString("温度4:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[3]));
    ui->cuntomplot1->replot(); // 更新重绘
}
// 获取湿度
void MainWindow::display_GetHumidity()
{
    m_waterwave_1->setvalue(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one);
    m_waterwave_2->setvalue(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_second);
    m_waterwave_3->setvalue(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_Three);
    //    m_waterwave_4->setvalue(m_pack_Control_To_PC_Humidity.m_Humidity_Data);
    // 湿度图表显示
    mGraph01->addData(mGraph01->dataCount(), m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one); // 温度1
    mGraph02->addData(mGraph02->dataCount(), m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_second);
    mGraph03->addData(mGraph03->dataCount(), m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_Three);
    //    mGraph04->addData(mGraph04->dataCount(), m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one);
    ui->cuntomplot2->xAxis->rescale();
    mGraph01->rescaleValueAxis(true, true);
    mGraph02->rescaleValueAxis(true, true);
    mGraph03->rescaleValueAxis(true, true);
    mGraph04->rescaleValueAxis(true, true);
    ui->cuntomplot2->xAxis->setRange(ui->cuntomplot2->xAxis->range().upper, 10, Qt::AlignRight); // 设置显示的点数
    mTag01->updatePosition(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one);
    mTag02->updatePosition(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_second);
    mTag03->updatePosition(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_Three);
    //    mTag04->updatePosition(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one);
    mTag01->setText(QString("湿度1:%1").arg(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one));
    mTag02->setText(QString("湿度2:%1").arg(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_second));
    mTag03->setText(QString("湿度3:%1").arg(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_Three));
    //    mTag04->setText(QString("湿度4:%1").arg(m_pack_Control_To_PC_Humidity.m_Humidity_Data.Hmidity_one));
    ui->cuntomplot2->replot(); // 更新重绘
}
// 获取水密舱存储器数据
void MainWindow::display_GetSASTankStatus()
{
    // 存储部分
    ui->percentage->setPersent(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fPercentage * 100);                                                                                                                                                                      // 存储系统利用率
    ui->totalStrage->setText(QString("%1GB已用,共%2GB").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fPercentage * m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fTotalStrage / 100).arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fTotalStrage)); // 存储系统容量
    // 已采集脉冲个数
    //    ui->numOfPluse->setText(QString::number(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.iNumOfPluse));
}
// 获取压力传感器数据
void MainWindow::display_GetPressureHeight()
{
    m_widgetPFD->setPressure(m_pack_Control_To_PC_PressureHeight.m_PressureHeight.fHeight); // 压力
    ui->Pressure->setText(QString::number(m_pack_Control_To_PC_PressureHeight.m_PressureHeight.fHeight));
}
// 获取压力传感器开关状态
void MainWindow::display_GetPressureHeightEn()
{
    QString GetPressureHeightEn_result;
    GetPressureHeightEn_result.sprintf("获取的深度开关状态为:%d", m_pack_PC_To_Control_PressureHeight_EN.PressureHeight_EN);
    ui->textBrowser->insertPlainText(GetPressureHeightEn_result);
}
// 获取姿态传感器数据
void MainWindow::display_GetAltitudeSensor()
{
    // 姿态传感器
    m_widgetPFD->setRoll(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fRoll - g_fRoll);          // 横滚角
    m_widgetPFD->setPitch(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fPitch - g_fPitch);       // 俯仰角
    m_widgetPFD->setHeading(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fHeading - g_fHeading); // 航向角
    m_widgetPFD->setAltitude(m_pack_Control_To_PC_PressureHeight.m_PressureHeight.fHeight);              // 海拔高度
    m_widgetPFD->setIdentifier("YGLC", true);
    m_widgetPFD->update();
    ui->Roll->setText(QString::number(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fRoll));
    ui->Pitch->setText(QString::number(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fPitch));
    ui->Heading->setText(QString::number(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fHeading));
}
// 获取姿态传感器开关状态
void MainWindow::display_GetAltitudeSensorEn()
{
    QString GetAltitudeSensorEn_result;
    GetAltitudeSensorEn_result.sprintf("获取的姿态开关状态为:%d", m_pack_PC_To_Control_AltitudeSensor_EN.AltitudeSensor_EN);
    ui->textBrowser->insertPlainText(GetAltitudeSensorEn_result);
}
// 获取声速数据
void MainWindow::display_GetSoundVelocity()
{
    QString GetSoundVelocity_result;
    GetSoundVelocity_result.sprintf("获取的声速数据为:%f", m_pack_PC_To_Control_SoundVelocity.sound_velocity);
    ui->textBrowser->insertPlainText(GetSoundVelocity_result);
}
// 获取高度传感器数据
void MainWindow::display_GetAltimeter()
{

    int ymin = 0, ymax = 0;
    ui->fHeight->setText(QString::number(m_pack_Control_To_PC_Altimeter.data[1]));
    //    ui->fConfidence->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fConfidence));
    //    ui->fPluseWidth->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fPluseWidth));
    //    ui->iD->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.iD));
    //    ui->fRange_Start->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fRange_Start));
    //    ui->fRange_Length->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fRange_Length));
    //    ui->fGain->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fGain));
    ui->iDataLength->setText(QString::number(m_pack_Control_To_PC_Altimeter.data[5]));
    ui->Altimeter->graph(0)->clearData();                                      // 清除图数据
    ui->Altimeter->xAxis->setRange(0, m_pack_Control_To_PC_Altimeter.data[5]); // 设置x轴范围
                                                                               // for (int i = 0; i < m_pack_Control_To_PC_Altimeter.m_Altimeter.data[5]; i++)
    for (int i = 0; i < 6; i++)
    {
        ui->Altimeter->graph(0)->addData(static_cast<double>(i), static_cast<double>(m_pack_Control_To_PC_Altimeter.data[i])); // 添加数据
        if (Altimeterdata[i] > ymax)
        {
            ymax = Altimeterdata[i];
        }
        if (Altimeterdata[i] < ymin)
        {
            ymin = Altimeterdata[i];
        }
    }
    ui->Altimeter->yAxis->setRange(ymin, ymax);
    ui->Altimeter->replot(); // 更新重绘
}
void MainWindow::display_SASTankStatus()
{
    //    //湿度部分
    //    m_waterwave_1->setvalue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[0]);
    //    m_waterwave_2->setvalue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[1]);
    //    m_waterwave_3->setvalue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[2]);
    //    m_waterwave_4->setvalue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[3]);
    //    //温度部分
    //    ui->thermometer1->setValue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[0]);  //温度1
    //    ui->thermometer2->setValue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[1]);  //温度2
    //    ui->thermometer3->setValue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[2]);  //温度3
    //    ui->thermometer4->setValue(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[3]);  //温度4
    //    //存储部分
    //    ui->percentage->setPersent(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fPercentage * 100); //存储系统利用率
    //    ui->totalStrage->setText(QString("%1GB已用,共%2GB").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fPercentage * m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fTotalStrage / 100).arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.fTotalStrage)); //存储系统容量
    //    //已采集脉冲个数
    //    ui->numOfPluse->setText(QString::number(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.iNumOfPluse));
    //    //漏水标识
    //    if(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.iLeaking == 1) {
    //        ui->waterflag->startAlarm();
    //    } else {
    //        ui->waterflag->stopAlarm();
    //        ui->waterflag->setBgColor(QColor(100, 184, 255));
    //    }
    //    //温度图表显示
    //    mGraph1->addData(mGraph1->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[0]); //温度1
    //    mGraph2->addData(mGraph2->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[1]);
    //    mGraph3->addData(mGraph3->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[2]);
    //    mGraph4->addData(mGraph4->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[3]);
    //    ui->cuntomplot1->xAxis->rescale();
    //    mGraph1->rescaleValueAxis(true, true);
    //    mGraph2->rescaleValueAxis(true, true);
    //    mGraph3->rescaleValueAxis(true, true);
    //    mGraph4->rescaleValueAxis(true, true);
    //    ui->cuntomplot1->xAxis->setRange(ui->cuntomplot1->xAxis->range().upper, 10, Qt::AlignRight);    //设置显示的点数
    //    mTag1->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[0]);
    //    mTag2->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[1]);
    //    mTag3->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[2]);
    //    mTag4->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[3]);
    //    mTag1->setText(QString("温度1:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[0]));
    //    mTag2->setText(QString("温度2:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[1]));
    //    mTag3->setText(QString("温度3:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[2]));
    //    mTag4->setText(QString("温度4:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Temperature[3]));
    //    ui->cuntomplot1->replot();  //更新重绘
    //    //湿度图表显示
    //    mGraph01->addData(mGraph01->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[0]); //温度1
    //    mGraph02->addData(mGraph02->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[1]);
    //    mGraph03->addData(mGraph03->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[2]);
    //    mGraph04->addData(mGraph04->dataCount(), m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[3]);
    //    ui->cuntomplot2->xAxis->rescale();
    //    mGraph01->rescaleValueAxis(true, true);
    //    mGraph02->rescaleValueAxis(true, true);
    //    mGraph03->rescaleValueAxis(true, true);
    //    mGraph04->rescaleValueAxis(true, true);
    //    ui->cuntomplot2->xAxis->setRange(ui->cuntomplot2->xAxis->range().upper, 10, Qt::AlignRight);    //设置显示的点数
    //    mTag01->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[0]);
    //    mTag02->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[1]);
    //    mTag03->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[2]);
    //    mTag04->updatePosition(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[3]);
    //    mTag01->setText(QString("湿度1:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[0]));
    //    mTag02->setText(QString("湿度2:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[1]));
    //    mTag03->setText(QString("湿度3:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[2]));
    //    mTag04->setText(QString("湿度4:%1").arg(m_pack_Control_To_PC_SASTankStatus.m_SASTankStatus.m_Tank_Status.Hmidity[3]));
    //    ui->cuntomplot2->replot();  //更新重绘
}

void MainWindow::display_SonarWorkingStatus()
{
    //    switch (m_pack_Control_To_PC_SonarWorkingStatus.SonarWorkingStatus) {
    //        case 1:
    //            ui->waterflag_3->setBgColor(Qt::GlobalColor::green);    //开始发射执行
    //            addLogMess("开始发射执行", Qt::GlobalColor::green);
    //            break;
    //        case 2:
    //            ui->waterflag_3->setBgColor(Qt::GlobalColor::red);      //停止发射执行
    //            addLogMess("停止发射执行", Qt::GlobalColor::red);
    //            break;
    //        case 3:
    //            ui->waterflag_3->setBgColor(Qt::GlobalColor::darkBlue);  //参数设置完成
    //            addLogMess("参数设置完成", Qt::GlobalColor::darkBlue);
    //            break;
    //        default:
    //            break;
    //    }
}

// void MainWindow::display_PressureHeight()
//{
//     m_widgetPFD->setPressure(m_pack_Control_To_PC_PressureHeight.m_PressureHeight.fHeight);         //压力
//     ui->Pressure->setText(QString::number(m_pack_Control_To_PC_PressureHeight.m_PressureHeight.fHeight));
// }

// void MainWindow::display_AltitudeSensor()
//{
//     //姿态传感器
//     m_widgetPFD->setRoll(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fRoll-g_fRoll);               //横滚角
//     m_widgetPFD->setPitch (m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fPitch-g_fPitch);            //俯仰角
//     m_widgetPFD->setHeading(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fHeading-g_fHeading);         //航向角
//     m_widgetPFD->setAltitude(m_pack_Control_To_PC_PressureHeight.m_PressureHeight.fHeight);         //海拔高度
//     m_widgetPFD->setIdentifier( "YGLC", true );
//     m_widgetPFD->update();
//     ui->Roll->setText(QString::number(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fRoll));
//     ui->Pitch->setText(QString::number(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fPitch));
//     ui->Heading->setText(QString::number(m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fHeading));
// }

// void MainWindow::display_Altimeter()
//{
//     int ymin = 0, ymax = 0;
//     ui->fHeight->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fHeight));
//     ui->fConfidence->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fConfidence));
//     ui->fPluseWidth->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fPluseWidth));
//     ui->iD->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.iD));
//     ui->fRange_Start->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fRange_Start));
//     ui->fRange_Length->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fRange_Length));
//     ui->fGain->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.fGain));
//     ui->iDataLength->setText(QString::number(m_pack_Control_To_PC_Altimeter.m_Altimeter.iDataLength));
//     ui->Altimeter->graph(0)->clearData();   //清除图数据
//     ui->Altimeter->xAxis->setRange(0, m_pack_Control_To_PC_Altimeter.m_Altimeter.iDataLength);  //设置x轴范围
//     for (int i = 0; i < m_pack_Control_To_PC_Altimeter.m_Altimeter.iDataLength; i++) {
//         ui->Altimeter->graph(0)->addData(static_cast<double>(i), static_cast<double>(Altimeterdata[i]));    //添加数据
//         if(Altimeterdata[i] > ymax) {
//             ymax = Altimeterdata[i];
//         }
//         if(Altimeterdata[i] < ymin) {
//             ymin = Altimeterdata[i];
//         }
//     }
//     ui->Altimeter->yAxis->setRange(ymin, ymax);
//     ui->Altimeter->replot();  //更新重绘
// }

void MainWindow::m_tcpclient_connected()
{
    ui->pushButton->setText("断开");
    /*  on_pushButton_Cur_Time_clicked();
      Sleep(100);
      on_pushButton_SetSignalType_clicked();
      Sleep(100);
      on_pushButton_SetWorkPower_clicked();
      Sleep(100);
      on_pushButton_SetTVG_clicked();
      Sleep(100);
      on_pushButton_SetWorkMode_clicked();
      Sleep(100);
      on_pushButton_Control_Signal_clicked();
      Sleep(100);
      on_pushButton_L_Sonar_clicked();
      Sleep(100);
      on_pushButton_R_Sonar_clicked();
      Sleep(100);
      */
}

void MainWindow::m_tcpclient_disconnected()
{
    ui->pushButton->setText("连接");
}

void MainWindow::m_tcpclient2_connected()
{
    ui->pushButton_CONNECT->setText("断开");
}
void MainWindow::m_tcpclient2_disconnected()
{
    ui->pushButton_CONNECT->setText("连接");
}

// 系统时间
void MainWindow::on_pushButton_Cur_Time_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Cur_Time();
        emit tcpwrite((char *)&m_pack_Control_To_PC_SystemTime, sizeof(m_pack_Control_To_PC_SystemTime));
        addLogMess("系统时间下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_GetSysTime_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Get_Time();
        emit tcpwrite((char *)&m_pack_Control_To_PC_SystemTime, sizeof(m_pack_Control_To_PC_SystemTime));
        addLogMess("获取系统时间下发成功", Qt::GlobalColor::darkBlue);
    }
}

// 信号类型
void MainWindow::on_pushButton_SetSignalType_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Set_SignalType_H();
        emit tcpwrite((char *)&m_pack_Control_To_SignalType_H, sizeof(m_pack_Control_To_SignalType_H));
        addLogMess("高频信号类型下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_SetSignalType_3_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Set_SignalType_L();
        emit tcpwrite((char *)&m_pack_Control_To_SignalType_L, sizeof(m_pack_Control_To_SignalType_L));
        addLogMess("低频信号类型下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_GetSignalType_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Get_SignalType_H();
        emit tcpwrite((char *)&m_pack_Control_To_SignalType_H, sizeof(m_pack_Control_To_SignalType_H));
        addLogMess("获取高频信号类型下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_GetSignalType_3_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Get_SignalType_L();
        emit tcpwrite((char *)&m_pack_Control_To_SignalType_L, sizeof(m_pack_Control_To_SignalType_L));
        addLogMess("获取低频信号类型下发成功", Qt::GlobalColor::darkBlue);
    }
}

// Gain增益
void MainWindow::on_pushButton_SetTVG_Gain_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Set_TVG_Gain();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TVG_Gain, sizeof(m_pack_PC_To_Control_TVG_Gain));
        addLogMess("TVG_Gain下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_GetTVG_Gain_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Get_TVG_Gain();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TVG_Gain, sizeof(m_pack_PC_To_Control_TVG_Gain));
        addLogMess("TVG_Gain下发成功", Qt::GlobalColor::darkBlue);
    }
}
// 发射功率
void MainWindow::on_pushButton_SetWorkPower_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_SetWorkPower();
        emit tcpwrite((char *)&m_pack_PC_To_Control_WorkPower, sizeof(m_pack_PC_To_Control_WorkPower));
        addLogMess("发射功率下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_GetWorkPower_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetWorkPower();
        emit tcpwrite((char *)&m_pack_PC_To_Control_WorkPower, sizeof(m_pack_PC_To_Control_WorkPower));
        addLogMess("获取发射功率下发成功", Qt::GlobalColor::darkBlue);
    }
}

// TVG参数
void MainWindow::on_pushButton_SetTVG_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_SetTVG_H();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TVG_H, sizeof(m_pack_PC_To_Control_TVG_H));
        addLogMess("TVG参数下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_SetTVG_2_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_SetTVG_L();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TVG_L, sizeof(m_pack_PC_To_Control_TVG_L));
        addLogMess("TVG参数下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_GetTVG_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetTVG_H();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TVG_H, sizeof(m_pack_PC_To_Control_TVG_H));
        addLogMess("获取TVG参数下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_GetTVG_2_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetTVG_L();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TVG_L, sizeof(m_pack_PC_To_Control_TVG_L));
        addLogMess("获取TVG参数下发成功", Qt::GlobalColor::darkBlue);
    }
}
// 工作方式
void MainWindow::on_pushButton_SetWorkMode_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_SetWorkMode();
        emit tcpwrite((char *)&m_pack_PC_To_Control_WorkMode, sizeof(m_pack_PC_To_Control_WorkMode));
        addLogMess("工作方式参数下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_GetWorkMode_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetWorkMode();
        emit tcpwrite((char *)&m_pack_PC_To_Control_WorkMode, sizeof(m_pack_PC_To_Control_WorkMode));
        addLogMess("获取工作方式下发成功", Qt::GlobalColor::darkBlue);
    }
}

// TEMP
void MainWindow::on_pushButton_GetTEMP_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetTEMP();
        emit tcpwrite((char *)&m_pack_Control_To_PC_TEMP, sizeof(m_pack_Control_To_PC_TEMP));
        addLogMess("获取温度下发成功", Qt::GlobalColor::darkBlue);
    }
}
// Humidity
void MainWindow::on_pushButton_GetHumidity_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetHumidity();
        emit tcpwrite((char *)&m_pack_Control_To_PC_Humidity, sizeof(m_pack_Control_To_PC_Humidity));
        addLogMess("获取湿度下发成功", Qt::GlobalColor::darkBlue);
    }
}
// 水密舱存储器
void MainWindow::on_pushButton_GetSASTankStatus_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetSASTankStatus();
        emit tcpwrite((char *)&m_pack_Control_To_PC_SASTankStatus, sizeof(m_pack_Control_To_PC_SASTankStatus));
        addLogMess("获取水密舱存储器下发成功", Qt::GlobalColor::darkBlue);
    }
}
// 压力传感器
void MainWindow::on_pushButton_GetPressureHeight_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetPressureHeight();
        emit tcpwrite((char *)&m_pack_Control_To_PC_PressureHeight, sizeof(m_pack_Control_To_PC_PressureHeight));
        addLogMess("获取压力传感器下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_bPressureEnable_clicked(bool checked)
{
    if (checked)
    {
        memset(&m_pack_PC_To_Control_PressureHeight_EN, 0, sizeof(m_pack_PC_To_Control_PressureHeight_EN));
        m_pack_PC_To_Control_PressureHeight_EN.PressureHeight_EN = 1;
        receive_SetPressureHeightEn();
        Sleep(100);
        receive_GetPressureHeightEn();
        Sleep(100);
    }
    else
    {
        memset(&m_pack_PC_To_Control_PressureHeight_EN, 0, sizeof(m_pack_PC_To_Control_PressureHeight_EN));
        m_pack_PC_To_Control_PressureHeight_EN.PressureHeight_EN = 0;
        receive_SetPressureHeightEn();
        Sleep(100);
        receive_GetPressureHeightEn();
        Sleep(100);
    }
}

void MainWindow::on_pushButton_GetAltitudeSensor_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetAltitudeSensor();
        emit tcpwrite((char *)&m_pack_Control_To_PC_AltitudeSensor, sizeof(m_pack_Control_To_PC_AltitudeSensor));
        addLogMess("获取姿态传感器下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_bAltitudeEnable_clicked(bool checked)
{
    if (checked)
    {
        memset(&m_pack_PC_To_Control_AltitudeSensor_EN, 0, sizeof(m_pack_PC_To_Control_AltitudeSensor_EN));
        m_pack_PC_To_Control_AltitudeSensor_EN.AltitudeSensor_EN = 1;
        receive_SetAltitudeSensorEn();
        Sleep(100);
        receive_GetAltitudeSensorEn();
        Sleep(100);
    }
    else
    {
        memset(&m_pack_PC_To_Control_AltitudeSensor_EN, 0, sizeof(m_pack_PC_To_Control_AltitudeSensor_EN));
        m_pack_PC_To_Control_AltitudeSensor_EN.AltitudeSensor_EN = 0;
        receive_SetAltitudeSensorEn();
        Sleep(100);
        receive_GetAltitudeSensorEn();
        Sleep(100);
    }
    //    qDebug() << m_pack_PC_To_Control_Signal.m_Control_Signal.bAltitudeEnable;
}
void MainWindow::on_pushButton_SaveEnable_clicked(bool checked)
{
    if (checked)
    {
        memset(&m_pack_PC_To_Control_AltitudeSensor_EN, 0, sizeof(m_pack_PC_To_Control_AltitudeSensor_EN));
        m_pack_PC_To_Control_SoundVelocity.sound_velocity = 1;
        receive_SetSoundVelocity();
        Sleep(100);
        receive_GetSoundVelocity();
        Sleep(100);
    }
    else
    {
        memset(&m_pack_PC_To_Control_SoundVelocity, 0, sizeof(m_pack_PC_To_Control_SoundVelocity));
        m_pack_PC_To_Control_SoundVelocity.sound_velocity = 0;
        receive_SetSoundVelocity();
        Sleep(100);
        receive_GetSoundVelocity();
        Sleep(100);
    }
}
// void MainWindow::on_pushButton_bAltitudeEnable_clicked()
//{
//     if(m_tcpclient->conectflag == true) {
//         receive_SetAltitudeSensorEn();
//         emit tcpwrite((char *)&m_pack_PC_To_Control_AltitudeSensor_EN, sizeof(m_pack_PC_To_Control_AltitudeSensor_EN));
//         addLogMess("姿态开关下发成功", Qt::GlobalColor::darkBlue);
//     }
// }

void MainWindow::on_pushButton_Working_Sonr_clicked(bool checked)
{
    if (m_tcpclient->conectflag == true)
    {
        if (checked)
        {
            memset(&m_pack_PC_To_Control_WokingStart, 0, sizeof(m_pack_PC_To_Control_WokingStart));
            m_pack_PC_To_Control_WokingStart.Massage_Header = 0xa55ab55b;
            m_pack_PC_To_Control_WokingStart.Device_Address = 0x05;
            m_pack_PC_To_Control_WokingStart.Opreation = 0x82;
            m_pack_PC_To_Control_WokingStart.KeyWord = 0x1103;
            m_pack_PC_To_Control_WokingStart.DataLength = sizeof(m_pack_PC_To_Control_L_Sonar.sonar);
            m_pack_PC_To_Control_WokingStart.Wokingsonar = 1;
            m_pack_PC_To_Control_WokingStart.Check_Sum = 0;
            m_pack_PC_To_Control_WokingStart.Massage_Tail = 0xff0d;
            emit tcpwrite((char *)&m_pack_PC_To_Control_WokingStart, sizeof(m_pack_PC_To_Control_WokingStart));
            usleep(100000);
            addLogMess("声纳打开，开始发射", Qt::GlobalColor::darkBlue);
            fWorken_flag = 1;
        }
        else
        {
            memset(&m_pack_PC_To_Control_WokingStart, 0, sizeof(m_pack_PC_To_Control_WokingStart));
            m_pack_PC_To_Control_WokingStart.Massage_Header = 0xa55ab55b;
            m_pack_PC_To_Control_WokingStart.Device_Address = 0x05;
            m_pack_PC_To_Control_WokingStart.Opreation = 0x82;
            m_pack_PC_To_Control_WokingStart.KeyWord = 0x1103;
            m_pack_PC_To_Control_WokingStart.DataLength = sizeof(m_pack_PC_To_Control_L_Sonar.sonar);
            m_pack_PC_To_Control_WokingStart.Wokingsonar = 0;
            m_pack_PC_To_Control_WokingStart.Check_Sum = 0;
            m_pack_PC_To_Control_WokingStart.Massage_Tail = 0xff0d;
            emit tcpwrite((char *)&m_pack_PC_To_Control_WokingStart, sizeof(m_pack_PC_To_Control_WokingStart));
            usleep(100000);
            addLogMess("声纳关闭，停止发射", Qt::GlobalColor::darkRed);
            fWorken_flag = 0;
        }
    }
}
void MainWindow::setfilename1(bool checked)
{
    if (checked)
    {
        on_pushButton_Cur_Time_clicked();
        Sleep(100);
        on_pushButton_SetSignalType_clicked();
        Sleep(100);
        on_pushButton_SetWorkPower_clicked();
        Sleep(100);
        on_pushButton_SetTVG_clicked();
        Sleep(100);
        on_pushButton_SetWorkMode_clicked();
        Sleep(100);
        on_pushButton_Control_Signal_clicked();
        Sleep(100);
        on_pushButton_L_Sonar_clicked();
        Sleep(100);
        on_pushButton_Triger_Sonar_clicked();
        Sleep(100);
    }
    else
    {
        on_pushButton_L_Sonar_clicked();
        Sleep(100);
        on_pushButton_Triger_Sonar_clicked();
        Sleep(100);
        on_pushButton_Control_Signal_clicked();
        Sleep(100);
    }
    //    if(m_tcpclient->conectflag == true) {
    //        if(checked) {
    //            m_pack_PC_To_Control_Working_Status.m_Control_Working_Status.Working_Status = 1;
    //            emit tcpwrite((char *)&m_pack_PC_To_Control_Working_Status, sizeof(m_pack_PC_To_Control_Working_Status));
    //            addLogMess("声纳打开，开始发射", Qt::GlobalColor::darkBlue);
    //        } else {
    //            m_pack_PC_To_Control_Working_Status.m_Control_Working_Status.Working_Status = 0;
    //            emit tcpwrite((char *)&m_pack_PC_To_Control_Working_Status, sizeof(m_pack_PC_To_Control_Working_Status));
    //            addLogMess("声纳关闭，停止发射", Qt::GlobalColor::darkRed);
    //        }
    //    }
}

// 下发采集参数
void MainWindow::on_pushButton_Control_Signal_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Signal_H();
        emit tcpwrite((char *)&m_pack_PC_To_Control_Signal_H, sizeof(m_pack_PC_To_Control_Signal_H));
        addLogMess("采集参数下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_pushButton_Control_Signal_2_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Control_Signal_L();
        emit tcpwrite((char *)&m_pack_PC_To_Control_Signal_L, sizeof(m_pack_PC_To_Control_Signal_L));
        addLogMess("采集参数下发成功", Qt::GlobalColor::darkBlue);
    }
}
// 下发采集参数

void MainWindow::on_pushButton_L_Sonar_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_LSnoar();
        emit tcpwrite((char *)&m_pack_PC_To_Control_L_Sonar, sizeof(m_pack_PC_To_Control_L_Sonar));
        addLogMess("声呐下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_Triger_Sonar_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_RSnoar();
        emit tcpwrite((char *)&m_pack_PC_To_Control_TrigerMode, sizeof(m_pack_PC_To_Control_TrigerMode));
        addLogMess("触发方式下发成功", Qt::GlobalColor::darkBlue);
    }
}
void MainWindow::on_actionabout_triggered()
{
    QString runPath = QCoreApplication::applicationDirPath(); // 获取exe路径
    QString qtManulFile = QString("%1/测试界面说明.pdf").arg(runPath);
    QDesktopServices::openUrl(QUrl::fromLocalFile(qtManulFile));
}

void MainWindow::on_pushButton_bSingle_1_clicked(bool checked)
{
    //    if(checked) {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_1 = 1;
    //    } else {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_1 = 0;
    //    }
    //    qDebug() << m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_1;
}

void MainWindow::on_pushButton_bSingle_2_clicked(bool checked)
{
    //    if(checked) {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_2 = 1;
    //    } else {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_2 = 0;
    //    }
    //    qDebug() << m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_2;
}

void MainWindow::on_pushButton_bSingle_3_clicked(bool checked)
{
    //    if(checked) {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_3 = 1;
    //    } else {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_3 = 0;
    //    }
    //    qDebug() << m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_3;
}

void MainWindow::on_pushButton_bSingle_4_clicked(bool checked)
{
    //    if(checked) {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_4 = 1;
    //    } else {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_4 = 0;
    //    }
    //    qDebug() << m_pack_PC_To_Control_Signal.m_Control_Signal.bSingle_4;
}

void MainWindow::on_pushButton_bAltimeterEnable_clicked(bool checked)
{
    //    if(checked) {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bAltimeterEnable = 1;
    //    } else {
    //        m_pack_PC_To_Control_Signal.m_Control_Signal.bAltimeterEnable = 0;
    //    }
    //    qDebug() << m_pack_PC_To_Control_Signal.m_Control_Signal.bAltimeterEnable;
}

void MainWindow::on_pushButton_CONNECT_clicked()
{
    if (ui->pushButton_CONNECT->text() == "连接")
    {
        emit setfilename(ui->lineEdit_floder->text()); // 先设置文件名字
        emit tcp2connect(ui->lineEdit_IP->text(), ui->lineEdit_PORT->text().toUShort());
    }
    else
    {
        emit tcp2disconnect();
    }
}

void MainWindow::on_pushButton_floder_clicked()
{
    QString FilePath; // 数据文件路径
    FilePath = QFileDialog::getExistingDirectory(this, "数据存盘路径", ui->lineEdit_floder->text(), QFileDialog ::DontUseNativeDialog);
    if (FilePath != "")
    {
        ui->lineEdit_floder->setText(FilePath + "/");
    }
}

////void MainWindow::on_pushButton_bAltimeterEnable_2_clicked(bool checked)
//{
////    if(checked) {
////        m_pack_PC_To_Control_AltimeterEnable.nAltimeterEnable = 1;
////        emit tcpwrite((char *)&m_pack_PC_To_Control_AltimeterEnable, sizeof(m_pack_PC_To_Control_AltimeterEnable));
////        addLogMess("高度传感器打开", Qt::GlobalColor::darkBlue);
////    } else {
////        m_pack_PC_To_Control_AltimeterEnable.nAltimeterEnable = 0;
////        emit tcpwrite((char *)&m_pack_PC_To_Control_AltimeterEnable, sizeof(m_pack_PC_To_Control_AltimeterEnable));
////        addLogMess("高度传感器关闭", Qt::GlobalColor::darkRed);
////    }
//}

void MainWindow::on_calibration_clicked()
{

    g_fHeading = m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fHeading; // 航向
    g_fPitch = m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fPitch;     // 俯仰
    g_fRoll = m_pack_Control_To_PC_AltitudeSensor.m_AltitudeSensor.fRoll;       // 横滚
}

// setfilename

void MainWindow::on_pushButton_Working_Status_clicked(bool checked)
{
    if (checked)
    {
        on_pushButton_Cur_Time_clicked();
        Sleep(100);
        on_pushButton_SetSignalType_clicked();
        Sleep(100);
        on_pushButton_SetWorkPower_clicked();
        Sleep(100);
        on_pushButton_SetTVG_clicked();
        Sleep(100);
        on_pushButton_SetWorkMode_clicked();
        Sleep(100);
        on_pushButton_Control_Signal_clicked();
        Sleep(100);
        on_pushButton_L_Sonar_clicked();
        Sleep(100);
        on_pushButton_Triger_Sonar_clicked();
        Sleep(100);
        qDebug() << "22";
    }
    else
    {
    }
}

void MainWindow::on_pushButton_2_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_infromtion();
        emit tcpwrite((char *)&m_Device_Information, sizeof(m_Device_Information));
        addLogMess("获取设备信息下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_3_clicked()
{
    if (m_tcpclient->conectflag == true)
    {
        receive_Voltage_And_Current();
        emit tcpwrite((char *)&m_Voltage_And_Current, sizeof(m_Voltage_And_Current));
        addLogMess("获取电压电流信息下发成功", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_Activity_clicked(bool checked)
{
    if (m_tcpclient->conectflag == true)
    {

        if (checked)
        {
            receive_Activity();
            emit tcpwrite((char *)&m_pack_PC_To_Control_Activity, sizeof(m_pack_PC_To_Control_Activity));
            addLogMess("活性检测开始", Qt::GlobalColor::darkBlue);
            fActivity_flag = 1;
            usleep(10000);
        }
        else
        {
            addLogMess("活性检测停止", Qt::GlobalColor::darkBlue);
            fActivity_flag = 0;
        }
    }
}

void MainWindow::on_pushButton_L_delay_clicked()
{
    memset(&m_pack_PC_To_Control_L_Delay, 0, sizeof(pack_PC_To_Control_L_Delay));
    m_pack_PC_To_Control_L_Delay.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_L_Delay.Device_Address = 0x05;
    m_pack_PC_To_Control_L_Delay.Opreation = 0x82;
    m_pack_PC_To_Control_L_Delay.KeyWord = 0x0111;
    m_pack_PC_To_Control_L_Delay.DataLength = sizeof(m_pack_PC_To_Control_L_Delay.Delay_Time);
    m_pack_PC_To_Control_L_Delay.Delay_Time = ui->lineEdit_L_delay->text().toInt();
    m_pack_PC_To_Control_L_Delay.Check_Sum = 0;
    m_pack_PC_To_Control_L_Delay.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_L_Delay, sizeof(pack_PC_To_Control_L_Delay));
    addLogMess("设置低频延时成功", Qt::GlobalColor::darkBlue);
}

void MainWindow::on_checkBox_floder_clicked(bool checked)
{
    emit setsavefileflag(checked);
    memset(&m_pack_PC_To_Control_SATA_Flag, 0, sizeof(pack_PC_To_Control_SATA_Flag));
    m_pack_PC_To_Control_SATA_Flag.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_SATA_Flag.Device_Address = 0x05;
    m_pack_PC_To_Control_SATA_Flag.Opreation = 0x82;
    m_pack_PC_To_Control_SATA_Flag.KeyWord = 0x0152;
    m_pack_PC_To_Control_SATA_Flag.DataLength = sizeof(m_pack_PC_To_Control_SATA_Flag.SATA_Flag);
    m_pack_PC_To_Control_SATA_Flag.SATA_Flag = checked;
    m_pack_PC_To_Control_SATA_Flag.Check_Sum = 0;
    m_pack_PC_To_Control_SATA_Flag.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_SATA_Flag, sizeof(pack_PC_To_Control_SATA_Flag));
    if (checked)
    {
        addLogMess("设置SATA打开", Qt::GlobalColor::darkBlue);
    }
    else
    {
        addLogMess("设置SATA关闭", Qt::GlobalColor::darkBlue);
    }
}

void MainWindow::on_pushButton_GetAltimeter_2_clicked(bool checked)
{
    if (m_tcpclient->conectflag == true)
    {
        receive_GetAltimeter();
        if(checked){
          m_pack_Control_To_PC_Altimeter.data[0] = 1;
        }else{
          m_pack_Control_To_PC_Altimeter.data[0] = 0;
        }

        emit tcpwrite((char *)&m_pack_Control_To_PC_Altimeter, sizeof(m_pack_Control_To_PC_Altimeter));
        addLogMess("获取高度计下发成功", Qt::GlobalColor::darkBlue);
    }
}

// 查询GPS星数
void MainWindow::on_GPS_Source_clicked()
{
    memset(&m_pack_PC_To_Control_GPS_SCOUNT, 0, sizeof(m_pack_PC_To_Control_GPS_SCOUNT));
    m_pack_PC_To_Control_GPS_SCOUNT.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_GPS_SCOUNT.Device_Address = 0x00;
    m_pack_PC_To_Control_GPS_SCOUNT.Opreation = 0x80;
    m_pack_PC_To_Control_GPS_SCOUNT.KeyWord = 0x0111;
    m_pack_PC_To_Control_GPS_SCOUNT.DataLength = sizeof(m_pack_PC_To_Control_GPS_SCOUNT.SartsCount);
    m_pack_PC_To_Control_GPS_SCOUNT.SartsCount = 0;
    m_pack_PC_To_Control_GPS_SCOUNT.Check_Sum = 0;
    m_pack_PC_To_Control_GPS_SCOUNT.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_GPS_SCOUNT, sizeof(m_pack_PC_To_Control_GPS_SCOUNT));
    addLogMess("获取GPS星数下发成功", Qt::GlobalColor::darkBlue);
}
// GPS查询UTC
void MainWindow::on_GPS_UTC_clicked()
{
    memset(&m_pack_PC_To_Control_GPS_UTC, 0, sizeof(m_pack_PC_To_Control_GPS_UTC));
    m_pack_PC_To_Control_GPS_UTC.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_GPS_UTC.Device_Address = 0x00;
    m_pack_PC_To_Control_GPS_UTC.Opreation = 0x80;
    m_pack_PC_To_Control_GPS_UTC.KeyWord = 0x0112;
    m_pack_PC_To_Control_GPS_UTC.DataLength = sizeof(m_pack_PC_To_Control_GPS_UTC.GPS_UTC);
    m_pack_PC_To_Control_GPS_UTC.GPS_UTC = 0;
    m_pack_PC_To_Control_GPS_UTC.Check_Sum = 0;
    m_pack_PC_To_Control_GPS_UTC.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_GPS_UTC, sizeof(m_pack_PC_To_Control_GPS_UTC));
    addLogMess("获取GPS的UTC下发成功", Qt::GlobalColor::darkBlue);
}

// 原子钟状态查询
void MainWindow::on_HCC_PPS_TIME_2_clicked()
{
    memset(&m_pack_PC_To_Control_HCC_STATE, 0, sizeof(m_pack_PC_To_Control_HCC_STATE));
    m_pack_PC_To_Control_HCC_STATE.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_HCC_STATE.Device_Address = 0x00;
    m_pack_PC_To_Control_HCC_STATE.Opreation = 0x80;
    m_pack_PC_To_Control_HCC_STATE.KeyWord = 0x0113;
    m_pack_PC_To_Control_HCC_STATE.DataLength = sizeof(m_pack_PC_To_Control_HCC_STATE.HCC_State);
    m_pack_PC_To_Control_HCC_STATE.HCC_State = 0;
    m_pack_PC_To_Control_HCC_STATE.Check_Sum = 0;
    m_pack_PC_To_Control_HCC_STATE.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_HCC_STATE, sizeof(m_pack_PC_To_Control_HCC_STATE));
    addLogMess("获取原子钟状态下发成功", Qt::GlobalColor::darkBlue);
}
// 原子钟驯服模式查询
void MainWindow::on_HCC_PPS_MODE_2_clicked()
{

    memset(&m_pack_Control_To_PC_HCC_MODE, 0, sizeof(m_pack_Control_To_PC_HCC_MODE));
    m_pack_Control_To_PC_HCC_MODE.Massage_Header = 0xa55ab55b;
    m_pack_Control_To_PC_HCC_MODE.Device_Address = 0x00;
    m_pack_Control_To_PC_HCC_MODE.Opreation = 0x80;
    m_pack_Control_To_PC_HCC_MODE.KeyWord = 0x0114;
    m_pack_Control_To_PC_HCC_MODE.DataLength = sizeof(m_pack_Control_To_PC_HCC_MODE.HCC_Mode);
    m_pack_Control_To_PC_HCC_MODE.HCC_Mode = 0;
    m_pack_Control_To_PC_HCC_MODE.Check_Sum = 0;
    m_pack_Control_To_PC_HCC_MODE.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_Control_To_PC_HCC_MODE, sizeof(m_pack_Control_To_PC_HCC_MODE));
    addLogMess("设置原子钟模式下发成功", Qt::GlobalColor::darkBlue);
}

// 原子钟驯服模式
void MainWindow::on_HCC_PPS_MODE_clicked()
{
    memset(&m_pack_PC_To_Control_HCC_MODE, 0, sizeof(m_pack_PC_To_Control_HCC_MODE));
    m_pack_PC_To_Control_HCC_MODE.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_HCC_MODE.Device_Address = 0x00;
    m_pack_PC_To_Control_HCC_MODE.Opreation = 0x82;
    m_pack_PC_To_Control_HCC_MODE.KeyWord = 0x0121;
    m_pack_PC_To_Control_HCC_MODE.DataLength = sizeof(m_pack_PC_To_Control_HCC_MODE.HCC_Mode);
    // m_pack_PC_To_Control_HCC_MODE.HCC_Mode = ui->comboBox_HCC_MODE->currentText().toInt();
    m_pack_PC_To_Control_HCC_MODE.HCC_Mode = static_cast<uint8_t>(ui->comboBox_HCC_MODE->currentIndex());
    m_pack_PC_To_Control_HCC_MODE.Check_Sum = 0;
    m_pack_PC_To_Control_HCC_MODE.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_HCC_MODE, sizeof(m_pack_PC_To_Control_HCC_MODE));
    addLogMess("设置原子钟模式下发成功", Qt::GlobalColor::darkBlue);
}

// 原子钟PPS校准
void MainWindow::on_HCC_PPS_TIME_clicked()
{
    memset(&m_pack_PC_To_Control_HCC_SYNC, 0, sizeof(m_pack_PC_To_Control_HCC_SYNC));
    m_pack_PC_To_Control_HCC_SYNC.Massage_Header = 0xa55ab55b;
    m_pack_PC_To_Control_HCC_SYNC.Device_Address = 0x00;
    m_pack_PC_To_Control_HCC_SYNC.Opreation = 0x82;
    m_pack_PC_To_Control_HCC_SYNC.KeyWord = 0x0122;
    m_pack_PC_To_Control_HCC_SYNC.DataLength = 0;
    m_pack_PC_To_Control_HCC_SYNC.Check_Sum = 0;
    m_pack_PC_To_Control_HCC_SYNC.Massage_Tail = 0xff0d;
    emit tcpwrite((char *)&m_pack_PC_To_Control_HCC_SYNC, sizeof(m_pack_PC_To_Control_HCC_SYNC));
    addLogMess("原子钟PPS校准下发成功", Qt::GlobalColor::darkBlue);
}

// GPS_星数
void MainWindow::onAltitudeUpdated(int altitude)
{
    ui->lineEdit_3->setText(QString::number(altitude));
}

// GPS_UTC
void MainWindow::onUTCUpdated(uint64_t utc)
{
    // ui->lineEdit_4->setText(QString::number(utc));
    time_t time_in_seconds = static_cast<time_t>(utc);

    // 将 time_t 转换为 struct tm
    struct tm *time_info = localtime(&time_in_seconds);

    // 格式化为字符串
    char buffer[20]; // 例如 "2023-09-22 14:55:54"
    strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", time_info);

    // 在文本框中显示格式化后的时间
    ui->lineEdit_4->setText(QString::fromUtf8(buffer));
}
// 原子钟状态显示
void MainWindow::onStateUpdated(int state)
{
    ui->lineEdit_5->setText(QString::number(state));
}

// 原子钟驯服模式显示
void MainWindow::onStateUpdated_Mode(uint8_t state)
{
    ui->lineEdit_6->setText(QString::number(state));
}
